#ifndef prs_FrmInteger_H
#define prs_FrmInteger_H

#include "prs_Rule.h"
#include "prs_FrmControl.h"
#include "prs_FrmUseTemplate.h"
#include "prs_FrmIntegerStyle.h"
#include "frm_control_TInteger.h"

#include "prs_CalcExpr.h"

namespace prs {
            
///////////////////////////////////////////////////////////////////////////////
struct TNodeFrmInteger;
///////////////////////////////////////////////////////////////////////////////

struct TNodeFrmIntegerControl : public frm::control::TInteger
{
  TNodeFrmIntegerControl(
    frm::control::TWindow &Window,
    TNodeFrmInteger &Node
  ):TInteger(Window),node(Node) {}
  //
  virtual bool UpdateValue(svl::TString V);
  
private:  
  TNodeFrmInteger &node;
};

///////////////////////////////////////////////////////////////////////////////

struct TNodeFrmInteger : public TNodeFrmControl
{
  DECLARE_ClientNode()
  //
  typedef TNodeFrmIntegerStyle   TStyle;
  typedef TNodeFrmIntegerControl TControl;
  //
  TAttrNodeType<nodeType_Integer> NodeType;
  TAttrBindPropInteger<attrName_Value, TNodeUseTemplateParam*> Value;
  TAttrBool<attrName_EnEdit> EnEdit;
  TAttrPointerNoCopy<attrName_Control,TNodeFrmIntegerControl*> Control;
  //
  TNodeFrmInteger():NodeType(this),Value(this),Control(this),EnEdit(this) {}
 ~TNodeFrmInteger() { delete Control.GetValue(); }
  
  TNodeFrmIntegerControl *BuildControl(
    frm::control::TPanel *ParentControl
  );
private:
  virtual void TNode_SetPropIntegerValue(TAttrIntegerBase &Attr,int V);
  virtual int  TNode_GetPropIntegerValue(TAttrIntegerBase &Attr);
  void updateValueInControl();
  //
  int value;
  svl::TLocksStack::TState St;
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////

struct TRuleFrmInteger : public snt::TRule, public TFrmDict
{
  TRuleFrmInteger(
    snt::text::TContext &Context,
    svl::TVariant &VParentNode,
    TRuleFrmChildrenBase &RFrmChildren,
    TRuleSetNodeIdOptionally &RSetNodeIdOptionally,
    TRuleSetAttrValue &RSetAttrValue,
    TRuleSetStyle &RStyle
  );

private:  
  bool FSetParamInteger(TRuleSetAttrValue::TFuncValueIdentParams &Params) {
    return TNodeDefTemplate::AddLinkAttrByParamId(Params.Attr,TFrmIntegerValue(),Params.Ident,Params.OutError);
  }
  bool FSetParamBool(TRuleSetAttrValue::TFuncValueIdentParams &Params) {
    return TNodeDefTemplate::AddLinkAttrByParamId(Params.Attr,TFrmBoolValue(),Params.Ident,Params.OutError);
  }
  //
  svl::TVariant &vParentNode;
  snt::TAlter AAttr1;
  snt::TRule  RAttr1,RAttr;
  
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////
}

#endif
